package com.zq.it.action.admin;

import java.util.List;

import javax.annotation.Resource;

import com.zq.it.action.BaseAction;
import com.zq.it.pojo.Address;
import com.zq.it.service.admin.TAddressService;
import com.zq.it.tool.EtyLsName;
import com.zq.it.tool.FileName;
import com.zq.it.tool.FileType;
import com.zq.it.tool.HeadTitle;

public class AddressAction extends BaseAction {
    private static final long serialVersionUID = 1L;
    @Resource
    private TAddressService   addressService;
    private Address           address;
    private String            type;
    private String            param;
    private Integer[]         adrIds;

    public void searchAdrList() {
        List list = addressService.getAllAddress();
        uploadList(EtyLsName.ADR_LS.name(), list);
        print(toJSON(list).toString(), "UTF-8", "APPLICATION/JSON");
    }

    public void addAdrPo() {
        addressService.addAddress(address);
        print("<SCRIPT>parent.closeWindow('已添加！')</SCRIPT>", "UTF-8", "TEXT/HTML");
    }

    public void searchAddrListFromType() {
        List list = addressService.getAddressListByType(param);
        uploadList(EtyLsName.ADR_LS.name(), list);
        print(toJSON(list).toString(), "UTF-8", "APPLICATION/JSON");
    }

    public void deleteAdrLs() {
        addressService.removeAllAddress(adrIds);
        print("已删除" + adrIds.length + "条记录！", "UTF-8", "text/html");
    }

    public void modifyAdrPo() {
        addressService.renewalAddress(address);
        print("<script>parent.closeWindow('已修改');</script>", "UTF-8", "text/html");
    }

    public void importAddrList() {
        String msgStr = "";
        List<Address> list = addressService.importAddressList(getUpload());
        if (list.size() > 0) {
            getRequest().getSession().setAttribute("existList", list);
            msgStr = "existList";
        } else {
            msgStr = "已导入成功!";
        }
        print("<script>parent.importBackResult('" + msgStr + "','webpage/adminpage/tAddress/existAdr.jsp');</script>",
                "UTF-8", "TEXT/HTML");
    }

    public void exportAdr() {
        download(
                addressService.exportAddressList(HeadTitle.CN_ADDRESSHEAD.getArray(),
                        (List<Address>) getHttpSession().getAttribute(EtyLsName.ADR_LS.name())),
                FileName.ADDRESS_LIST_NAME.toString() + FileType.XLSX);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getParam() {
        return param;
    }

    public void setParam(String param) {
        this.param = param;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Integer[] getAdrIds() {
        return adrIds;
    }

    public void setAdrIds(Integer[] adrIds) {
        this.adrIds = adrIds;
    }
}
